let p1 = Promise.resolve('success')
// console.log(p1);
p1.then(res => {
  console.log(res); 
})

let p2 = Promise.reject('fail')
p2.catch(err => {
  console.log(err);
})

function foo(flag) {
  if(flag) {
    return new Promise(resolve => {
      resolve('success')
    }) 
  }else {
    return Promise.reject('fail')
  }
}

foo(false).then().catch(err => {})

// promise.all  参数是异步的集合 全部成功才返回参数
promise.all([p1, p2, p3]).then(res => { 
  console.log(res);
}, err => {
  console.log(err);
})


// 谁先返回,就返回哪个结果,不管状态成功还是失败
promise.race([p1, p2, p3]).then(res => {
  console.log(res);
})


//图片上传云数据库
const imgArr = ['img1', 'img2', 'img3']
let primiseArr = []
imgArr.forEach(item => {
  promiseArr.push(new Promise((resolve, reject) => {
    resolve(url)
  }))
})

Promise.all(promiseArr).then(res => {
  console.log(res); // 返回数组, 包含所有结果
})

//